home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / MultiView.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  5.2 KB  |  145 lines

  1. package symantec.itools.db.pro;
  2.  
  3. import java.io.EOFException;
  4. import java.util.Properties;
  5. import java.util.Vector;
  6. import symantec.itools.db.net.NetData;
  7. import symantec.itools.db.net.RemoteObject;
  8. import symjava.sql.SQLException;
  9.  
  10. public class MultiView {
  11.    private RelationView _rootRV;
  12.    private RemoteObject _messgr;
  13.    private byte _rvCurrentID = 0;
  14.    private int _proxyID;
  15.    RecordTree _rootRecord = new RecordTree();
  16.    boolean _closed = false;
  17.    private Properties _rootRVCtorProperties;
  18.    final int METHOD_fetchRecords;
  19.    final int METHOD_OnDataChange = 1;
  20.    final int METHOD_save = 2;
  21.    final int METHOD_isDataChanged = 3;
  22.    final int METHOD_undoChanges = 4;
  23.    final int METHOD_undoRecord = 5;
  24.    final int METHOD_deleteRecord = 6;
  25.    final int METHOD_getNewRecord = 7;
  26.    final int METHOD_close = 8;
  27.    final int METHOD_getStream = 9;
  28.    final int METHOD_restart = 10;
  29.  
  30.    MultiView(Session session, Vector ctorParams, ConnectionInfo conn) throws SQLException {
  31.       NetData d = (NetData)ctorParams.elementAt(0);
  32.  
  33.       int id;
  34.       try {
  35.          id = d.getInt();
  36.       } catch (EOFException e) {
  37.          throw new SQLException(((Throwable)e).getMessage());
  38.       }
  39.  
  40.       this._proxyID = id;
  41.       this._messgr = new RemoteObject("CSCLMultiView", id, session.getClientSession());
  42.       ctorParams.removeElementAt(0);
  43.       this.saveRootRVProperties(session, ctorParams, conn);
  44.    }
  45.  
  46.    private void saveRootRVProperties(Session session, Vector ctorParams, ConnectionInfo conn) {
  47.       this._rootRVCtorProperties = new Properties();
  48.       this._rootRVCtorProperties.put("session", session);
  49.       this._rootRVCtorProperties.put("ctorParams", ctorParams);
  50.       this._rootRVCtorProperties.put("conn", conn);
  51.       this.getNextLevelID();
  52.    }
  53.  
  54.    Properties getRootRVCtorProperties() {
  55.       return this._rootRVCtorProperties;
  56.    }
  57.  
  58.    void setRootRelView(RelationView rv) {
  59.       this._rootRV = rv;
  60.    }
  61.  
  62.    byte getNextLevelID() {
  63.       byte var10002 = this._rvCurrentID;
  64.       this._rvCurrentID = (byte)(var10002 + 1);
  65.       return var10002;
  66.    }
  67.  
  68.    byte getCurrentLevelID() {
  69.       return this._rvCurrentID;
  70.    }
  71.  
  72.    private void checkClosed() throws SQLException {
  73.       if (this._closed) {
  74.          throw new SQLException("MultiView has been closed");
  75.       }
  76.    }
  77.  
  78.    void freeRecordBuffer(boolean fullReset) throws SQLException {
  79.       this.checkClosed();
  80.       this._rootRecord.freeRecordBlocks();
  81.       this._rootRecord = new RecordTree();
  82.       this.getRootRelView().resetRecordSet(fullReset);
  83.    }
  84.  
  85.    public synchronized void close() throws SQLException {
  86.       this.checkClosed();
  87.       this._messgr.invokeMethod(8);
  88.       this.freeRecordBuffer(true);
  89.       this._messgr.disable();
  90.       this._closed = true;
  91.    }
  92.  
  93.    public RelationView getRootRelView() throws SQLException {
  94.       if (this._rootRV == null) {
  95.          ConnectionInfo conn = (ConnectionInfo)this._rootRVCtorProperties.get("conn");
  96.          this._rootRV = new RelationView(this, (byte)0, conn);
  97.       }
  98.  
  99.       return this._rootRV;
  100.    }
  101.  
  102.    public boolean isDataChanged() throws SQLException {
  103.       this.checkClosed();
  104.       if (!this.getRootRelView().notifySetData()) {
  105.          return true;
  106.       } else {
  107.          Vector results = this._messgr.invokeMethod(3);
  108.          NetData d = (NetData)results.elementAt(0);
  109.  
  110.          try {
  111.             return d.getBool();
  112.          } catch (EOFException e) {
  113.             throw new SQLException(((Throwable)e).getMessage());
  114.          }
  115.       }
  116.    }
  117.  
  118.    public void save() throws SQLException {
  119.       this.checkClosed();
  120.       if (this.getRootRelView().notifySetData()) {
  121.          this._messgr.invokeMethod(2);
  122.          this.freeRecordBuffer(false);
  123.       }
  124.  
  125.    }
  126.  
  127.    public void restart() throws SQLException {
  128.       this.checkClosed();
  129.       this._messgr.invokeMethod(10);
  130.       this.freeRecordBuffer(false);
  131.    }
  132.  
  133.    public void undoDataChanges() throws SQLException {
  134.       this.checkClosed();
  135.       this._messgr.invokeMethod(4);
  136.       this.freeRecordBuffer(false);
  137.    }
  138.  
  139.    RecordSet getRecordSet(RelViewPos pos) throws SQLException {
  140.       this.checkClosed();
  141.       pos.setMVRemObj(this._messgr);
  142.       return this._rootRecord.getRecordSet(pos.reset());
  143.    }
  144. }
  145.